import { any } from "../core/logic"
import { guid } from "../core/utils";

class Texture{
    constructor(opts){
        let { image, dimension, viewDimension, format, usage, sampler, multisampled, sampleType, uvIndex, uvTransform, texture } = opts;
        this.format = any(format, 'rgba8unorm');
        this.dimension = any(dimension, '2d');
        this.viewDimension = any(viewDimension, '2d');
        this.usage = any(usage, GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT);
        this.sampler = any(sampler, {
            addressModeU: "repeat",
            addressModeV: "repeat",
            addressModeW: "repeat",
            magFilter: "linear",
            minFilter: "linear",
            mipmapFilter: "linear"
        });
        this.multisampled = any(multisampled, false);
        this.sampleType = any(sampleType, 'float');
        this.uvIndex = uvIndex;
        this.uvTransform = uvTransform;
        this.image = image;
        this.texture = texture;
        this.id=any(opts.id,guid())
        this.mipMap=any(opts.mipMap,true)
        this.bigTextureQuality=any(opts.bigTextureQuality,1.0)
    }
    get format() {
        return this._format
    }
    set format(v) {
        this._format = v;
        return this;
    }
    get dimension() {
        return this._dimension
    }
    set dimension(v) {
        this._dimension = v;
        return this;
    }
    get viewDimension() {
        return this._viewDimension
    }
    set viewDimension(v) {
        this._viewDimension = v;
        return this;
    }
    get usage() {
        return this._usage
    }
    set usage(v) {
        this._usage = v;
        return this;
    }
    get sampler() {
        return this._sampler
    }
    set sampler(v) {
        this._sampler = v;
        return this;
    }
    get multisampled() {
        return this._multisampled
    }
    set multisampled(v) {
        this._multisampled = v;
        return this;
    }
    get sampleType() {
        return this._sampleType
    }
    set sampleType(v) {
        this._sampleType = v;
        return this;
    }
    get uvIndex() {
        return this._uvIndex
    }
    set uvIndex(v) {
        this._uvIndex = v;
        return this;
    }
    get uvTransform() {
        return this._uvTransform
    }
    set uvTransform(v) {
        this._uvTransform = v;
        return this;
    }
    get image() {
        return this._image
    }
    set image(v) {
        this._image = v;
        return this;
    }
    get texture() {
        return this._texture
    }
    set texture(v) {
        this._texture = v;
        return this;
    }
    toGPU() {
        let { image, texture, dimension, viewDimension, format, usage, sampler, multisampled, sampleType, uvIndex, uvTransform } = this;
        return {
            image,
            dimension,
            viewDimension,
            format,
            usage,
            sampler,
            multisampled,
            sampleType,
            uvIndex,
            uvTransform,
            texture
        }
    }
    
}
export {Texture}